
import store from '@/store'
// 将localStorage的用户信息存在store中
export const setStoreUserInfo = function () {
  let userInfo = localStorage.getItem('userInfo')
  userInfo && store.commit('setUserInfo', JSON.parse(userInfo))
  console.log('进入setStoreUserInfo')
  console.log(store.state);
};
// 页面loading
export const loading = function (loading) {
  store.commit('setLoading', loading)
};

// 时间格式2019-07-05T03:56:21.000+0000 转为正常格式 2019-07-05 00:00:00
export const renderTime = function (date) {
  var dateee = new Date(date).toJSON();
  return new Date(+new Date(dateee) + 8 * 3600 * 1000)
    .toISOString()
    .replace(/T/g, " ")
    .replace(/\.[\d]{3}Z/, "")
    .toLocaleString();
};
// url拼接
export const setUrl = function (filePath, fileName) {
  return `http://${filePath}/${fileName}`
};
// 过去文件类型
export const getType = function (str) {
  let index = str.indexOf("/");
  let type = str.slice(0, index);
  return type
};
// 截取日期 xxxx-xx-xx
export const sliceTime = function (time) {
  return time.slice(0, 10);
};
//下载文件
export const downloadFile = function (response,fileName) {
  const blob = new Blob([response.data]);
  var downloadElement = document.createElement("a");
  var href = window.URL.createObjectURL(blob); //创建下载的链接
  downloadElement.href = href; 
  downloadElement.download = fileName;//下载后文件名
  document.body.appendChild(downloadElement);
  downloadElement.click();//点击下载
  document.body.removeChild(downloadElement);//下载完成移除元素
  window.URL.revokeObjectURL(href); //释放掉blob对象
};
// 列表分页序号处理
export const listNum = function (current,index) {
  return (( current - 1 ) * 10) + (index + 1)
}